package com.sc.reducer;

import java.io.IOException;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import com.sc.bean.SpendSecond;

public class StaffPartReducer extends Reducer<Text, SpendSecond, Text, SpendSecond> {

	//优化代码
	SpendSecond spendSecond = new SpendSecond();
	FloatWritable moneyf = new FloatWritable();
	Text city = new Text();
	
	@Override
	protected void reduce(Text arg0, Iterable<SpendSecond> arg1,
			Reducer<Text, SpendSecond, Text, SpendSecond>.Context arg2) throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		float money = 0;
		for (SpendSecond m : arg1) {
			money += m.getMoney().get();
			city = m.getCity();
		}
		
		spendSecond.setName(arg0);
		spendSecond.setCity(city);
		moneyf.set(money);
		spendSecond.setMoney(moneyf);
		arg2.write(arg0, spendSecond);
	}
}
